/**
 * 4
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-10 下午6:50
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> tasks;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            tasks.push_back(x);
        }
        sort(tasks.begin(), tasks.end());
        vector<int> tasksSorted(tasks.begin(), tasks.end());

        long long res = 0;
        for (int i = 0; i < k; i++) {
            res += tasksSorted[i];
        }
        long long aSum = 0;
        long long bSum = res;
        for (int i = 0; i < k; i++) {
            aSum += tasksSorted[i];
            bSum -= tasksSorted[i];
            res = min(res, max(aSum, bSum));
        }
        cout << res << endl;
    }
}